﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using System.Reflection;
using log4net;
using Microsoft.ApplicationBlocks.Data;


namespace AnyOffice.general.system.security
{
    public partial class index : ModulePage
    {

        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                ConfigManager manager = new ConfigManager();
                if (this.rblVirifyCode.Items.FindByValue(manager.SecurityVerifyCode.ToString().ToLower()) != null)
                {
                    this.rblVirifyCode.Items.FindByValue(manager.SecurityVerifyCode.ToString().ToLower()).Selected = true;
                }
                if (this.rblRember.Items.FindByValue(manager.SecurityRember.ToString().ToLower()) != null)
                {
                    this.rblRember.Items.FindByValue(manager.SecurityRember.ToString().ToLower()).Selected = true;
                }
                if (this.rblLoginKey.Items.FindByValue(manager.LoginKey.ToString().ToLower()) != null)
                {
                    this.rblLoginKey.Items.FindByValue(manager.LoginKey.ToString().ToLower()).Selected = true;
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                try
                {
                    string commandText = " UPDATE [dbo].[Sys_Para] SET [ParaValue]= @ParaValue WHERE ParaName='SECURITY_VERIFYCODE'";
                    SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@ParaValue", SqlDbType.NText) };
                    commandParameters[0].Value = this.rblVirifyCode.SelectedValue;
                    SqlHelper.ExecuteNonQuery(base.Conn, CommandType.Text, commandText, commandParameters);
                    commandText = " UPDATE [dbo].[Sys_Para] SET [ParaValue]= @ParaValue WHERE ParaName='SECURITY_REMBER'";
                    commandParameters[0].Value = this.rblRember.SelectedValue;
                    SqlHelper.ExecuteNonQuery(base.Conn, CommandType.Text, commandText, commandParameters);
                    commandText = " UPDATE [dbo].[Sys_Para] SET [ParaValue]= @ParaValue WHERE ParaName='LOGIN_KEY'";
                    commandParameters[0].Value = this.rblLoginKey.SelectedValue;
                    SqlHelper.ExecuteNonQuery(base.Conn, CommandType.Text, commandText, commandParameters);
                    ConfigManager.Update();
                    this.litMessage.Text = base.ShowPrompt("设置成功", "index.aspx");
                }
                catch (Exception exception)
                {
                    this.litMessage.Text = base.ShowPrompt("设置失败", "index.aspx");
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception);
                    }
                }
            }
        }

    }
}
